/*
 * Created by SharpDevelop.
 * User: David
 * Date: 2006-12-14
 * Time: 20:03
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using Labb4.Entity;

namespace Labb4.Pooman.Cards
{
	/// <summary>
	/// A graphical representation of a card
	/// </summary>
	public class GraphicalCard
	{
		#region members
		
		/// <summary>
		/// The sprite entity graphically representing the card
		/// </summary>
		private SpriteEntity		m_Pic;
		/// <summary>
		/// The graphical region where this graphical card is reciding
		/// </summary>
		private CardArea			m_Area;
		/// <summary>
		/// Determines if this card is selected or not, where true means selected
		/// </summary>
		private bool				m_Selected;
		/// <summary>
		/// Determines if this card was selected the last time it was checked
		/// </summary>
		private bool				m_SelectedPreviousFrame;
		
		/// <summary>
		/// The original x coordinate of this graphical representation. Used to logically move the
		/// card back to it's original position when not selected
		/// </summary>
		private float				m_OriginalXpos;
		/// <summary>
		/// The original y coordinate of this graphical representation. Used to logically move the
		/// card back to it's original position when not selected
		/// </summary>
		private float				m_OriginalYpos;
		/// <summary>
		/// The speed of the graphical representation when moving from one location to another
		/// </summary>
		private float				m_Speed;
		
		#endregion
		
		#region constructors
		
		public GraphicalCard(SpriteEntity pic)
		{
			m_Pic = pic;
			m_Pic.Controler = new ControlDestination();
			m_Area = null;
			m_Selected = false;
			m_SelectedPreviousFrame = false;
			
			m_OriginalXpos = 0.0f;
			m_OriginalYpos = 0.0f;
			m_Speed = 240.0f;
		}
		
		#endregion
		
		#region methods
		
		public bool HasPoint(ref int x, ref int y)
		{
			bool hasPoint = false;
			
			if(m_Pic.HasPoint(ref x, ref y))
			{
				if(m_Pic.PointIsColor(ref x, ref y))
				{
					hasPoint = true;
				}
			}
			
			return hasPoint;
		}
		
		public void HighlightCard(bool highlighted)
		{
			if(highlighted)
			{
				m_Pic.SelectAnimation("highlighted");
			}
			else
			{
				m_Pic.SelectAnimation("normal");
			}
		}
		
		public void SelectCard(bool selected)
		{
			//change the position of the card, selected cards are popped up over, or out from, other cards
			m_Selected = selected;
			
			if(m_Area != null)
			{
				float x = m_Pic.Xpos;
				float y = m_Pic.Ypos;
				
				if(!m_Area.Vertical)
				{
					if(selected)
					{
						if(!m_SelectedPreviousFrame)
						{
							y -= 40.0f;
						}
					}
					else
					{
						if(m_SelectedPreviousFrame)
						{
							y += 40.0f;
						}
					}
				}
				
				m_Pic.Controler.AddDestination((int)x, (int)y, m_Speed);
				m_SelectedPreviousFrame = m_Selected;
			}
		}
		
		public void PositionCard(float x, float y, CardArea area)
		{
			m_OriginalXpos = x;
			m_OriginalYpos = y;
			m_Area = area;
			
			m_Pic.Xpos = x;
			m_Pic.Ypos = y;
		}
		
		#endregion
		
		#region properties
		
		public SpriteEntity Pic
		{
			get
			{
				return m_Pic;
			}
		}
		
		#endregion
	}
}
